package it.tempogara;
import com.cloudgarden.layout.AnchorLayout;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.*;
import javax.swing.border.BevelBorder;
import javax.swing.event.MouseInputAdapter;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Launch extends javax.swing.JFrame {
	private JPanel jPanel1;
	private JTextField jTextFieldF3;
	private JLabel jLabel1;
	private JTextField jTextFieldF2;
	private JLabel jLabelF3;
	private JLabel jLabelF2;
	private JLabel jLabelF1;
	private JButton jButtonFile;
	private JButton jButtonFile2;
	private JButton jButtonRun;
	private JTextField jTextField1;

	private File[] files;
	private JLabel jLabelCatJun;
	private JTextField jTextFieldCatPro;
	private JLabel jLabelCatProm;
	private JTextField jTextFieldCatAll;
	private JLabel jLabelCatAll;
	private JTextField jTextFieldAll;
	private JLabel jLabelALL;
	private JCheckBox jCheckoOrdinamento;
	private JTextField jTextFieldCatJun;
	private JLabel jLabelJunF;
	private JTextField jTextFieldSenF;
	private JTextField jTextFieldJunF;
	private JTextField jTextFieldProF;
	private JTextField jTextFieldAllF;
	private JLabel jLabelSenF;
	private JLabel jLabelProF;
	private JLabel jLabelAllF;
	private JTextField jTextFieldCatSen;
	private JLabel jLabelCatSen;
	private File target;
	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				Launch inst = new Launch();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
				inst.setPreferredSize(new Dimension(1000, 1000));
			}
		});
	}
	
	public Launch() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			{
				jPanel1 = new JPanel();
				getContentPane().add(jPanel1, BorderLayout.CENTER);
				jPanel1.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
				jPanel1.setLayout(null);
				jPanel1.setPreferredSize(new java.awt.Dimension(929, 1000));
				jPanel1.setSize(884, 762);
				{
					jButtonFile2 = new JButton();
					jPanel1.add(jButtonFile2);
					jButtonFile2.setText("Scegli cartella di destinazione");
					jButtonFile2.setBounds(334, 314, 217, 23);
					jButtonFile2.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent e) {
							JFileChooser inputFile = new JFileChooser();
							inputFile.setMultiSelectionEnabled(false);
							inputFile.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
							if (inputFile.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
								target=inputFile.getSelectedFile();
							}
						}
						
						
					});
					
				}
				{
					jButtonFile = new JButton();
					jPanel1.add(jButtonFile);
					jButtonFile.setText("Carica file delle classifiche");
					jButtonFile.setBounds(350, 63, 197, 23);
					jButtonFile.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent e) {
							JFileChooser inputFile = new JFileChooser();
							inputFile.setMultiSelectionEnabled(true);
							inputFile.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
							if (inputFile.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
								files = inputFile.getSelectedFiles();
								jButtonRun.setEnabled(true);
							}
						}
						
						
					});
				}
				{
					jLabelF1 = new JLabel();
					jPanel1.add(jLabelF1);
					jLabelF1.setText("Nome classification fascia 1 MASTER");
					jLabelF1.setBounds(41, 114, 235, 16);
				}
				{
					jLabelF2 = new JLabel();
					jPanel1.add(jLabelF2);
					jLabelF2.setText("Nome classification fascia 2 MASTER");
					jLabelF2.setBounds(41, 154, 235, 16);
				}
				{
					jLabelF3 = new JLabel();
					jPanel1.add(jLabelF3);
					jLabelF3.setText("Nome classification fascia 3 MASTER");
					jLabelF3.setBounds(41, 190, 235, 16);
				}
				{
					jTextFieldF2 = new JTextField();
					jPanel1.add(jTextFieldF2);
					jTextFieldF2.setBounds(276, 151, 62, 23);
				}
				{
					jTextFieldF3 = new JTextField();
					jPanel1.add(jTextFieldF3);
					jTextFieldF3.setBounds(276, 187, 62, 23);
				}
				{
					jTextField1 = new JTextField();
					jPanel1.add(jTextField1);
					jTextField1.setBounds(276, 111, 62, 23);
				}
				{
					jButtonRun = new JButton();
					jPanel1.add(jButtonRun);
					jButtonRun.setText("Genera");
					jButtonRun.setBounds(281, 423, 316, 55);
					jButtonRun.setEnabled(false);
					jButtonRun.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent e) {
							String[] paths=new String[files.length];
							for(int i=0;i<files.length;i++)
								paths[i]=files[i].getAbsolutePath();
							Engine engine=null;
							try {
								engine = new Engine(new String[]{jTextField1.getText(),jTextFieldF2.getText(),jTextFieldF3.getText(),jTextFieldAll.getText()},paths);
							} catch (Exception e2) {
								// TODO Auto-generated catch block
								e2.printStackTrace();
							}
							if(target!=null)
								engine.setDestination(target.getAbsolutePath());
							//			            	if(!jTextFieldPF1.getText().isEmpty())
								//			            		engine.setPuntPart1(Integer.valueOf(jTextFieldPF1.getText()));
							//			            	if(!jTextFieldPF2.getText().isEmpty())
								//			            		engine.setPuntPart2(Integer.valueOf(jTextFieldPF2.getText()));
							//			            	if(jCheckBoxMaschile.isSelected())
								//			            		engine.setMaschile(true);
							//			            	if(jCheckBoxFemminile.isSelected())
								//			            		engine.setFemminile(true);
							//			            	if(!jCheckBoxFemminile.isSelected() && !jCheckBoxMaschile.isSelected()){
								//			            		engine.setMaschile(true);
								//			            		engine.setFemminile(true);
								//			            	}	
							String categorie="";
							if(jTextFieldCatAll.getText().isEmpty())
								categorie+="AM";
							else
								categorie+=jTextFieldCatAll.getText();
							if(jTextFieldCatPro.getText().isEmpty())
								categorie+=",PM";
							else
								categorie+=","+jTextFieldCatPro.getText();
							if(jTextFieldCatJun.getText().isEmpty())
								categorie+=",JM";
							else
								categorie+=","+jTextFieldCatJun.getText();
							if(jTextFieldCatSen.getText().isEmpty())
								categorie+=",SM";
							else
								categorie+=","+jTextFieldCatSen.getText();
							if(jTextFieldAllF.getText().isEmpty())
								categorie+=",AF";
							else
								categorie+=jTextFieldAllF.getText();
							if(jTextFieldProF.getText().isEmpty())
								categorie+=",PF";
							else
								categorie+=","+jTextFieldProF.getText();
							if(jTextFieldJunF.getText().isEmpty())
								categorie+=",JF";
							else
								categorie+=","+jTextFieldJunF.getText();
							if(jTextFieldSenF.getText().isEmpty())
								categorie+=",SF";
							else
								categorie+=","+jTextFieldSenF.getText();
							engine.setCategorie(categorie);
							if(jCheckoOrdinamento.isSelected())
								engine.setOrdinamentoClassificati(true);
							try {
								String[] cats = categorie.split(",");
								for(String cat : cats){
									engine.runSeparated(cat);
								}
								engine.run();
								JOptionPane.showMessageDialog(jPanel1, "Generazione completa");
								
							} catch (Exception e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							}
						}
					});
				}
				{
					jCheckoOrdinamento = new JCheckBox();
					jPanel1.add(jCheckoOrdinamento);
					jCheckoOrdinamento.setText("Ordina per numero classificati");
					jCheckoOrdinamento.setBounds(334, 368, 217, 20);
				}
				{
					jLabelALL = new JLabel();
					jPanel1.add(jLabelALL);
					jLabelALL.setText("Nome classification Allievi, Junior, Promesse, Senior");
					jLabelALL.setBounds(466, 115, 338, 16);
				}
				{
					jTextFieldAll = new JTextField();
					jPanel1.add(jTextFieldAll);
					jTextFieldAll.setBounds(786, 112, 59, 23);
				}
				{
					jLabelCatAll = new JLabel();
					jPanel1.add(jLabelCatAll);
					jLabelCatAll.setText("Nome categoria Allievi  M");
					jLabelCatAll.setBounds(350, 154, 161, 16);
				}
				{
					jTextFieldCatAll = new JTextField();
					jPanel1.add(jTextFieldCatAll);
					jTextFieldCatAll.setBounds(529, 151, 61, 23);
				}
				{
					jLabelCatProm = new JLabel();
					jPanel1.add(jLabelCatProm);
					jLabelCatProm.setText("Nome categoria promesse M");
					jLabelCatProm.setBounds(350, 190, 179, 16);
				}
				{
					jTextFieldCatPro = new JTextField();
					jPanel1.add(jTextFieldCatPro);
					jTextFieldCatPro.setBounds(529, 187, 62, 23);
				}
				{
					jLabelCatJun = new JLabel();
					jPanel1.add(jLabelCatJun);
					jLabelCatJun.setText("Nome categoria Junior M");
					jLabelCatJun.setBounds(350, 224, 153, 16);
				}
				{
					jTextFieldCatJun = new JTextField();
					jPanel1.add(jTextFieldCatJun);
					jTextFieldCatJun.setBounds(529, 221, 62, 23);
				}
				{
					jLabelCatSen = new JLabel();
					jPanel1.add(jLabelCatSen);
					jLabelCatSen.setText("Nome categoria Senior M");
					jLabelCatSen.setBounds(350, 260, 153, 16);
				}
				{
					jTextFieldCatSen = new JTextField();
					jPanel1.add(jTextFieldCatSen);
					jTextFieldCatSen.setBounds(529, 257, 62, 23);
				}
				{
					jLabelAllF = new JLabel();
					jPanel1.add(jLabelAllF);
					jLabelAllF.setText("Nome Categoria Allievi F");
					jLabelAllF.setBounds(608, 154, 149, 16);
				}
				{
					jLabelProF = new JLabel();
					jPanel1.add(jLabelProF);
					jLabelProF.setText("Nome Categoria Promesse F");
					jLabelProF.setBounds(609, 186, 183, 16);
				}
				{
					jLabelJunF = new JLabel();
					jPanel1.add(jLabelJunF);
					jLabelJunF.setText("Nome Categoria Junior F");
					jLabelJunF.setBounds(609, 224, 148, 16);
				}
				{
					jLabelSenF = new JLabel();
					jPanel1.add(jLabelSenF);
					jLabelSenF.setText("Nome Categoria Senior F");
					jLabelSenF.setBounds(609, 260, 148, 16);
				}
				{
					jTextFieldAllF = new JTextField();
					jPanel1.add(jTextFieldAllF);
					jTextFieldAllF.setBounds(790, 150, 62, 23);
				}
				{
					jTextFieldProF = new JTextField();
					jPanel1.add(jTextFieldProF);
					jTextFieldProF.setBounds(790, 183, 62, 23);
				}
				{
					jTextFieldJunF = new JTextField();
					jPanel1.add(jTextFieldJunF);
					jTextFieldJunF.setBounds(790, 221, 62, 23);
				}
				{
					jTextFieldSenF = new JTextField();
					jPanel1.add(jTextFieldSenF);
					jTextFieldSenF.setBounds(790, 257, 62, 23);
				}
			}
			{
			}
			this.setSize(900, 600);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public String actionProva(){
		return null;
		
	}

}
